package org.innovasix.logging;

import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class CustomFormatter extends Formatter {

	@Override
	public String format(LogRecord record) {
		StringBuilder sb = new StringBuilder();
		sb.append(String.format("%-8s", record.getLevel()));
		sb.append("[");
		sb.append(substring(record.getLoggerName()));
		sb.append("] ");
		sb.append(record.getMessage());
		sb.append(System.getProperty("line.separator"));
		return sb.toString();
	}
	
	
	private String substring(String loggerName){
		String[] segments = loggerName.split("\\.");
		if(segments.length == 0) 
			return loggerName;
		else
			return segments[segments.length-1];	
	}

}
